/**
* 
* ====================================================================
*
* @author apov <apov@ymail.com>
*/ 
#pragma once

#include <BaseDefine.h>
#include <string>
#include <Thread.h>
#include <PoplarPool.h>
#include "SessionSync.h"

class Network_IOListener;
class NetworkSession;
class NetInstanceBuilder{
public:
	virtual Network_IOListener* createListener( std::string force_poller, size_t server_port ) = 0;
	virtual NetworkSession* createSession( size_t server_port ) = 0;
	virtual void deleteSession( NetworkSession* session, size_t server_port ) = 0;	

	NetInstanceBuilder(){}
	virtual ~NetInstanceBuilder(){}

protected:
	CLock lock_;

private:
	
};

#ifdef WIN32

#include "SessionOverlapped.h"

class NetInstanceBuilderWindows : public NetInstanceBuilder{
public:
	virtual Network_IOListener* createListener( std::string force_poller, size_t server_port );
	virtual NetworkSession* createSession( size_t server_port );
	virtual void deleteSession( NetworkSession* session, size_t server_port );	

	NetInstanceBuilderWindows();
	virtual ~NetInstanceBuilderWindows();

protected:

private:
	ObjectPool<SessionOverlapped> instance_ovl_;
	ObjectPool<SessionSync> instance_sync_;
};

#endif

#ifdef LINUX

class NetInstanceBuilderLinux : public NetInstanceBuilder{
public:
	virtual Network_IOListener* createListener( std::string force_poller, size_t server_port );
	virtual NetworkSession* createSession( size_t server_port );
	virtual void deleteSession( NetworkSession* session, size_t server_port );
	
	NetInstanceBuilderLinux();
	virtual ~NetInstanceBuilderLinux();

protected:

private:
	ObjectPool<SessionSync> instance_sync_;
	//boost::default_user_allocator_new_delete, boost::details::pool::default_mutex
	//boost::object_pool<SessionSync> instance_sync_;
};

#endif

#ifdef OSX
class NetInstanceBuilderOsX : public NetInstanceBuilder{
public:
	virtual Network_IOListener* createListener( std::string force_poller, size_t server_port );
	virtual NetworkSession* createSession( size_t server_port );
	virtual void deleteSession( NetworkSession* session, size_t server_port );
	
	NetInstanceBuilderOsX();
	virtual ~NetInstanceBuilderOsX();

protected:

private:
	ObjectPool<SessionSync> instance_sync_;
};
#endif